package com.weimin.mqtt.server.model;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.function.Function;

@Data
@NoArgsConstructor
public class MqttSessionPublishMessage {
    /**
     * 客户端 IP
     */
    private String clientIp;
    /**
     * 通道连接 ID
     */
    private String connectId;
    /**
     * 主题
     */
    private String topic;
    /**
     * 内容
     */
    private byte[] content;
    /**
     * 内容类型  1 文本 -1 二进制
     */
    private int contentType = 1;
    /**
     * mqtt 回复消息 发布方法
     */
    private Function<MqttSessionPublishMessage, Boolean> publisher;

    public MqttSessionPublishMessage(String connectId, String topic, byte[] content) {
        this.connectId = connectId;
        this.topic = topic;
        this.content = content;
    }


    public MqttSessionPublishMessage(String clientIp, String connectId, String topic, byte[] content, Function<MqttSessionPublishMessage, Boolean> publisher) {
        this.clientIp = clientIp;
        this.connectId = connectId;
        this.topic = topic;
        this.content = content;
        this.publisher = publisher;
    }

    public boolean isEmpty() {
        return connectId == null || connectId.length() == 0 || topic == null || topic.length() == 0 || content == null || content.length == 0;
    }
}
